<?php
/**
 * Created by.
 * User: littleU-569598569
 * Date: 2021/3/28 0028
 * Time: 10:45
 */

namespace app\api\service;

use app\api\model\ProductAppendix as ProductAppendixModel;


class ProductAppendix extends BaseService
{
    public static function getNormalList()
    {
        $condition = [];
        $condition['status'] = config('code.normal');
        $result = (new ProductAppendixModel())->where($condition)->select();
        return json([
            'code' => config('code.success'),
            'data' => $result
        ]);
    }

    public static function setProductAppendix($data)
    {
        $id = $data['id'];
        if($id != '')
        {
            //更新
            try
            {
                $model = new ProductAppendixModel();
                $model->allowField(true)->save($data, ['id' => $id]);
            }
            catch (\Exception $ex)
            {
                return json([
                    'code' => config('code.error'),
                    'msg'  => $ex->getMessage()
                ]);
            }

        }
        else
        {
            //新增
            try
            {
                $model = new ProductAppendixModel();
                $model->allowField(true)->save($data);
            }
            catch (\Exception $ex)
            {
                return json([
                    'code' => config('code.error'),
                    'msg'  => $ex->getMessage()
                ]);
            }
        }
        return json([
            'code' => config('code.success'),
            'msg'  => '操作成功'
        ]);
    }
}